home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE03 / TYPECAST / COLOURSU.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-08  |  1KB  |  65 lines

  1. unit Coloursu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Label3: TLabel;
  16.     LowLbl: TLabel;
  17.     HighLbl: TLabel;
  18.     WholeLbl: TLabel;
  19.     procedure Button1Click(Sender: TObject);
  20.     procedure Button2Click(Sender: TObject);
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. var
  36.   LoWord, HiWord: Longint;
  37.   Tag: Longint;
  38. begin
  39.   Color := RGB(Random(256), Random(256), Random(256));
  40.   Tag := Color;
  41.   LoWord := Tag and $FFFF;
  42.   HiWord := Tag shr 16;
  43.   HighLbl.Caption := '$' + IntToHex(HiWord, 4);
  44.   LowLbl.Caption := '$' + IntToHex(LoWord, 4);
  45.   WholeLbl.Caption := '$' + IntToHex(Tag, 8);
  46. end;
  47.  
  48. procedure TForm1.Button2Click(Sender: TObject);
  49. var
  50.   LoWord, HiWord: Longint;
  51.   Tag: Longint;
  52. begin
  53.   Color := RGB(Random(256), Random(256), Random(256));
  54.   Tag := Color;
  55.   LoWord := Word(Tag);
  56.   HiWord := LongRec(Tag).Hi;
  57.   HighLbl.Caption := '$' + IntToHex(HiWord, 4);
  58.   LowLbl.Caption := '$' + IntToHex(LoWord, 4);
  59.   WholeLbl.Caption := '$' + IntToHex(Tag, 8);
  60. end;
  61.  
  62. initialization
  63.   Randomize;
  64. end.
  65.